package com.zy.yun.core.config;

import com.alibaba.fastjson.JSONObject;
import com.zy.yun.base.entity.Res;
import com.zy.yun.provider.service.IResService;
import com.zy.yun.utils.TableCacheUtil;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

import java.util.List;


/**
  * @Author: 王彦委
  * @Description: spring security 权限认证  //启用方法级的权限认证
  * @Date: 8:06 2019/11/6
  */
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

	@Autowired
	private TableCacheUtil tableCacheUtil;

	// 拦截所有请求,使用httpBasic方式登陆
	@Override
	protected void configure(HttpSecurity http) throws Exception {

		//初始化表缓存到redis中
		tableCacheUtil.setTableCache();

		//不需要权限认证
		http.authorizeRequests()
		        .antMatchers("/**")
				.permitAll()
				.and()
				.logout()
				.logoutUrl("/quit")
				.and()
				.formLogin().and().csrf().disable();
	}


}